package com.filyar.htyd.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.filyar.htyd.common.Result;
import com.filyar.htyd.entity.Person;
import com.filyar.htyd.service.IBranchService;
import com.filyar.htyd.service.IPersonService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author filyar
 * @since 2024-08-29
 * @e-mail root@filyar.com
 */
@RestController
@RequestMapping("/person")
public class PersonController {

    @Resource
    private IPersonService personService;
    @Resource
    private IBranchService branchService;

    private final String now = DateUtil.now();

    @PostMapping
    public Result save(@RequestBody Person person) {
        personService.saveOrUpdate(person);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        personService.removeById(id);
        return Result.success();
    }

    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        personService.removeByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(personService.getById(id));
    }

    @GetMapping("/page")
    public Result findPage(@RequestParam(defaultValue = "") String realName,
                           @RequestParam(defaultValue = "") String phone,
                           @RequestParam Integer pageNum,
                           @RequestParam Integer pageSize) {


        return Result.success(personService.customPage(new Page<Person>(pageNum, pageSize), realName, phone));
    }



}

